# -*- coding:utf-8 -*-

# @Time : 2023/3/17 10:28
# @Author : 快乐的小猴子
# @Version : 
# @Function : 

import requests
import random
from conf import settings


class SetProxies():
    def get_proxies(seif):
        # API接口，返回格式为json
        api_url = "https://kps.kdlapi.com/api/getkps/?secret_id=o41qghid3pb5kyydo46g&num=1&signature=fl2o1vb2172i4mgwsv3f9kwvebq5gmaw&pt=1&format=&sep=1"

        # # API接口返回的ip
        proxy_ip = requests.get(api_url).json()['data']['proxy_list']

        # 用户名密码认证(私密代理/独享代理)
        username = settings.username
        password = settings.password
        proxies = {
            "http": "http://%(user)s:%(pwd)s@%(proxy)s/" % {"user": username, "pwd": password,
                                                            "proxy": random.choice(proxy_ip)},
            "https": "http://%(user)s:%(pwd)s@%(proxy)s/" % {"user": username, "pwd": password,
                                                             "proxy": random.choice(proxy_ip)}
        }
        # print(proxies)
        return proxies

